package com.example.controller;

import com.example.domain.Meteorology;
import com.example.domain.Result;
import com.example.service.MeteorologyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/metes")
public class MeteorologyController {

    @Autowired
    private MeteorologyService meteorologyService;

    @GetMapping
    public Result getAll(){
        return new Result(true, meteorologyService.getAll());
    }

    @GetMapping("{meteorologyId}")
    public Result getById(@PathVariable Integer meteorologyId){
        return new Result(true,meteorologyService.getById(meteorologyId));
    }

    @PostMapping
    public Result add(@RequestBody Meteorology meteorology) {
        boolean code = meteorologyService.add(meteorology);
        return new Result(code);
    }

    @PutMapping
    public Result update(@RequestBody Meteorology meteorology){
        boolean code = meteorologyService.update(meteorology);
        return new Result(code);
    }

    @DeleteMapping("{meteorologyId}")
    public Result delete(@PathVariable Integer meteorologyId){
        boolean code = meteorologyService.delete(meteorologyId);
        return new Result(code);
    }
}
